package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/Demo2")
public class Demo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求的用户名
        String username = req.getParameter("username");
        //获取httpsession的对象
        HttpSession session = req.getSession();
        System.out.println(session);
        System.out.println(session.getId());

        //把用户名添加到共享数据中
        session.setAttribute("username",username);
        resp.setHeader("Refresh","2;URL=/stu/demo3.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
